/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package be.wim;

import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinState;
import com.pi4j.io.gpio.RaspiPin;

/**
 *
 * @author Wim
 */
public class Blink {
    
    final GpioController fGpioController = GpioFactory.getInstance();
    GpioPinDigitalOutput fLedPin;
    
    public Blink()
    {
        fLedPin = fGpioController.provisionDigitalOutputPin(RaspiPin.GPIO_01, "LED", PinState.LOW);
        blink(2000);
    }
    
    private void blink(int pInterval)
    {
        fLedPin.high();
        sleep(pInterval);
        fLedPin.low();
        sleep(pInterval);
        fLedPin.toggle();
        sleep(pInterval);
        fLedPin.toggle();
        sleep(pInterval);
        fLedPin.pulse(pInterval);
        sleep(pInterval);
    }
    
    private void sleep(int pInterval)
    {
        try {
            Thread.sleep(pInterval);
        } catch (InterruptedException ex) {
            fGpioController.shutdown();
        }
    }
    
}
